#ifndef PROCESSMONITOR_H
#define PROCESSMONITOR_H

#include <windows.h>
#include <QObject>
#include <QTimer>
#include <QStringList>
#include <QList>
#include <QMap>
#include "ProcessInfo.h"

// 存储进程上一次的时间数据
struct ProcessTimeData
{
    qint64 kernelTime;
    qint64 userTime;
    qint64 systemTime;
};

class ProcessMonitor : public QObject
{
    Q_OBJECT
public:
    explicit ProcessMonitor(QObject *parent = nullptr);

    // 设置需监控的游戏进程列表
    void setGameProcessNames(const QStringList &processNames);

public slots:
    // 启动监控
    void startMonitor(int interval = 2000);
    // 停止监控
    void stopMonitor();
    // 获取当前所有进程信息
    QList<ProcessInfo> getAllProcessWithCpuUsage();

signals:
    // 检测到游戏进程时触发
    void gameProcessDetected(const QString &processName);
    // 所有进程信息更新时触发
    void allProcessUpdated(const QList<ProcessInfo> &processList);

private slots:
    // 定时检测违规进程
    void checkProcesses();
    // 定时刷新所有进程信息
    void refreshAllProcessInfo();

private:
    QTimer *m_timer;
    QTimer *m_allProcessTimer;
    QStringList m_gameProcessNames;
    QMap<DWORD, ProcessTimeData> m_lastProcessTimes;
    QList<ProcessInfo> m_processList;
};

#endif // PROCESSMONITOR_H
